//
//  ViewController.m
//  UIDynamic
//
//  Created by MyMac on 15/6/11.
//  Copyright (c) 2015年 MyMac. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *redBtn;



@property (weak, nonatomic) IBOutlet UIButton *blue;
@property(strong,nonatomic)UIDynamicAnimator*animator;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    int(^TempBlock)(NSUInteger count,NSString*name);
    TempBlock=^(NSUInteger count,NSString*name){
        return 3;
      
    };
    int ret=  TempBlock(1000,@"dsadasd");
    NSLog(@"%d",ret);
    UIDynamicAnimator*an=[[UIDynamicAnimator alloc]initWithReferenceView:self.view];
      self.animator=an;
   
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

//只有遵循了UIDynamicItem协议的对象才能做物理仿真，UIView默认遵循了UIDynamicItem协议，，可以去文档里面看 
//    UIGravityBehavior*gravity=[[UIGravityBehavior alloc]initWithItems:@[self.redBtn]];
//   // gravity.gravityDirection=CGVectorMake(1, 1);
//   //gravity.angle=M_PI_2;//设置重力方向，，与上面的属性一样
//    gravity.magnitude=0.5;//重力加速度
//    [self.animator addBehavior:gravity];
//    UICollisionBehavior*collision=[[UICollisionBehavior alloc]initWithItems:@[self.redBtn,self.blue]];
    //- (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier forPath:(UIBezierPath*)bezierPath;自定义一个边界
   // - (void)addBoundaryWithIdentifier:(id <NSCopying>)identifier fromPoint:(CGPoint)p1 toPoint:(CGPoint)p2;//自定义一个边界线
//    collision.translatesReferenceBoundsIntoBoundary=YES;
//    //NSLog(@"%@",gravity.items);
//    [self.animator addBehavior:collision];
    UITouch*touch=[touches anyObject];
    CGPoint point=[touch locationInView:self.view];
    NSLog(@"%@  %@",NSStringFromCGRect(self.redBtn.frame),NSStringFromCGRect(self.blue.frame));//真是位置改变了
    UISnapBehavior*sna=[[UISnapBehavior alloc]initWithItem:self.redBtn snapToPoint:point];
    [self.animator removeAllBehaviors];//必须先移除其他行为
    sna.damping=1.0;//点中后震荡的幅度
    [self.animator addBehavior:sna];
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
//  NSUInteger a=  (NSUInteger)(^Block)(NSUInteger count,NSString*name)=^(NSUInteger count,NSString*name){
//      return 5;
//    
//    
//  };
  
    // Dispose of any resources that can be recreated.
}

@end
